package com.basic.bio.chat.groupchat;

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

/**
 * @Description:
 * @Date: 2024-03-28 20:07
 * @Author: wz
 **/
public class ClientSendThread extends Thread{
    private Socket socket;


    public ClientSendThread(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        System.out.println("客户端开始发消息咯。。。");
        try {
            Scanner scanner = new Scanner(System.in);
            System.out.println("请说：");
            OutputStream os = socket.getOutputStream();
            BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os));
            while (scanner.hasNextLine()){
                String msg = scanner.nextLine();
                writer.write(msg);
                writer.newLine();
                writer.flush();
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
